""""
def print_(i: str) -> str:
    i.replace("\\", "\\\\")
    return "say " + i
"""
import time

_1 = time.time()

import zipfile
import os

w = os.walk("./mods/")
mods = []
for (dirpath, dirnames, filenames) in w:
    for filename in filenames:
        if filename.split(".")[-1] == "zip":
            mods.append(filename)

for mod in mods:
    mod: str
    zip_file = zipfile.ZipFile("./mods/" + mod)
    zip_list = zip_file.namelist()  # 得到压缩包里所有文件
    for f in zip_list:
        zip_file.extract(f, "D:/temp/PCF/mods/")  # 循环解压文件到指定目录
    zip_file.close()  # 关闭文件，必须有，释放内存

w = os.walk("D:/temp/PCF/mods/")
modsFile = []
for (dirpath, dirnames, filenames) in w:
    for filename in filenames:
        modsFile.append((dirpath.split("/")[-1], dirpath + "/" + filename))

_t = []

for modFile in modsFile:
    _t2 = True
    for i in _t:
        if i[0] == modFile[0]:
            i[1].append(modFile[1])
            _t2 = False
            break
    if _t2:
        _t.append((modFile[0], [modFile[1]]))

for i in _t:
    _t3 = ""
    f = open(i[0] + ".py", "w", encoding="utf-8")
    for j in i[1]:
        _f = open(j, "r", encoding="utf-8")
        _t3 += _f.read()
        _t3 += "\n"
        _f.close()
    f.write(_t3)
    f.close()

print("初始化完成, 耗时" + str(time.time() - _1) + "s")
